package net.anzhuo.service.impl;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsBranchMapper;
import net.anzhuo.entity.GsBranch;
import net.anzhuo.service.GsBranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GsBranchServiceImpl implements GsBranchService {

	@Autowired
	private GsBranchMapper gsBranchMapper;

	@Override
	public PaginationVO<GsBranch> getListWithPage(GsBranch gsBranch) {
		PaginationVO<GsBranch> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsBranchMapper.getListWithPage(gsBranch));
		paginationVO.setTotalCount(gsBranchMapper.getCount(gsBranch));
		paginationVO.setTotalPage((gsBranchMapper.getCount(gsBranch) + gsBranch.getPageSize() -1)  / gsBranch.getPageSize());
		paginationVO.setPageNo(gsBranch.getPageNo());
		return paginationVO;
	}

	@Override
	public GsBranch getById(Long id) {
		return gsBranchMapper.getById(id);
	}

	@Override
	public List<GsBranch> getList() {
		return gsBranchMapper.getList();
	}

	@Override
	public List<GsBranch> getList(GsBranch gsBranch) {
		return gsBranchMapper.getListByQuery(gsBranch);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsBranch gsBranch) {
		gsBranchMapper.update(gsBranch);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsBranch gsBranch) {
		gsBranchMapper.save(gsBranch);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsBranch gsBranch) {
		gsBranchMapper.delete(gsBranch);
	}

	@Override
	public List<GsBranch> getByMd5(String md5) {
		return gsBranchMapper.getByMd5(md5);
	}
}
